package Algorithms.chapter2_1;

import java.io.BufferedInputStream;
import java.util.Scanner;

public class Quicksort {

    public static void main(String[] args) {
        Scanner in = new Scanner(new BufferedInputStream(System.in));
        int n = in.nextInt();
        int[] arr = new int [n];
        for (int i = 0; i < n; i++) {
            arr[i] = in.nextInt();
        }
        QuickSort(arr,0,n-1);
        for (int i = 0; i < n; i++) {
            System.out.println(arr[i]+" ");
        }
    }

    public static void QuickSort(int[] nums, int lo, int hi){
        if(lo>=hi){
            return;
        }
        int v = nums[lo],i = lo-1,j = hi+1;
        while (i<j){
            while(nums[++i]<v);
            while(nums[--j]>v);
            if(i<j){
                int t = nums[i];
                nums[i] = nums[j];
                nums[j] = t;
            }
        }
        QuickSort(nums,lo,j);
        QuickSort(nums,j+1,hi);
    }
}
